#include <boost/asio.hpp>
#include "torrent/PeerWire.hpp"
#include "gtest/gtest.h"

TEST(HandshakeReadWrite, streamReadWriteTest)
{
	peer_wire::HandShake hsWriter, hsReader;

	hsWriter._pstr = "bittorrent";
	hsWriter._infoHash = "abcdefghijklmnopqrst";
	hsWriter._peerID = "12345678901234567890";

	boost::asio::streambuf b;
	hsWriter.write(b);
	std::istream is(&b);
	char read_pstrlen = 0;
	is.get(read_pstrlen);

	EXPECT_EQ(hsWriter._pstr.length(), read_pstrlen);

	hsReader.read(b, hsWriter._pstr.length());

	EXPECT_STREQ(hsReader._pstr.c_str(), hsWriter._pstr.c_str());
	EXPECT_STREQ(hsReader._infoHash.c_str(), hsWriter._infoHash.c_str());
	EXPECT_STREQ(hsReader._peerID.c_str(), hsWriter._peerID.c_str());
}

// what is last test. cant remember ;;